/**
 * 
 */
package edu.bu.grocery.backingbean;

import java.io.IOException;

import javax.faces.context.FacesContext;

import edu.bu.grocery.session.UserSession;

/**
 * This will redirect the user if they are currently not logged in. 
 * @author donlanp
 *
 */
public class PageListenerBean {

	private UserSession session;
	
	/**
	 * If the user isn't logged in, redirect to index.faces
	 * @throws IOException 
	 */
	public void check() throws IOException{
		System.out.println("Checking login...");
		if(session.getCurrentUser() == null){
			FacesContext.getCurrentInstance().getExternalContext().redirect("index.faces");
		}
	}
	

	/**
	 * @return the session
	 */
	public UserSession getSession() {
		return session;
	}

	/**
	 * @param session the session to set
	 */
	public void setSession(UserSession session) {
		this.session = session;
	}
	
	
}
